package com.dit.action.dashboard;

import com.dit.action.claims.ClaimDocumentListView;
import com.dit.action.claims.ClaimsView;
import com.dit.action.customer.CustomerView;
import com.dit.action.customer.RoleManagementView;
import com.dit.action.messages.MessageView;
import com.dit.action.myAccount.MyAccountView;
import com.dit.action.payment.PaymentDetailsView;
import com.dit.action.payment.PaymentHistoryView;
import com.dit.action.payment.PaymentSchedule;
import com.dit.action.payment.PaymentView;
import com.dit.action.policy.AddMemberView;
import com.dit.action.policy.CreatePolicyView;
import com.dit.action.policy.PolicyDetailsView;
import com.dit.action.policy.PolicyView;
import com.dit.action.settings.SettingsView;
import com.dit.entity.UserLogin;
import com.dit.util.SessionHelper;
import com.dit.util.SessionKey;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.server.FontAwesome;
import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Link;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

public class DashboardView extends CustomComponent implements View {

	CustomerView customer = new CustomerView();
	MyAccountView myAccount = new MyAccountView();
	SettingsView settings = new SettingsView();
	PolicyView policy = new PolicyView();
	PaymentView payment = new PaymentView();
	ClaimsView claims = new ClaimsView(); 
	MessageView msg = new MessageView();
	
	private static final long serialVersionUID = 1L;

	public static final String NAME = "dashboard";
	
	@AutoGenerated
	private VerticalLayout mainLayout;

	
	public DashboardView() {
		buildMainLayout();
		setCompositionRoot(mainLayout);

		// TODO add user code here
	}

	
	@AutoGenerated
	private void buildMainLayout() {
		mainLayout = new VerticalLayout();
		/*mainLayout.setWidth("100%");
		mainLayout.setHeight("100%");

		setWidth("100.0%");
		setHeight("100.0%");*/
		
		Component header = createHeader();
		
		mainLayout.addComponent(header);
		mainLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER);
		
		Component tabs = createTabs();
		
		
		mainLayout.addComponent(tabs);
		mainLayout.setComponentAlignment(tabs, Alignment.MIDDLE_CENTER);
		
		
		
	}
	
	private Component createHeader() {
		Panel panel_2 = new Panel();
		
		Link link_1 = new Link("Sign Out", null);
		link_1.setIcon(FontAwesome.SIGN_OUT);
		link_1.setStyleName("h6-blue");
		link_1.setSizeUndefined();
		
		Label title = new Label("SME Portal");
		title.setStyleName("h2");
//		title.setWidthUndefined();
		title.setWidth(null);
		
		
		HorizontalLayout headerLayout = new HorizontalLayout(title,link_1);
		headerLayout.setMargin(true);
		headerLayout.setSpacing(true);
		headerLayout.setComponentAlignment(link_1, Alignment.TOP_RIGHT);
		headerLayout.setComponentAlignment(title, Alignment.MIDDLE_RIGHT);
		headerLayout.setSizeFull();
		/*headerLayout.setWidth("100%");
		headerLayout.setHeight("100%");

		setWidth("100.0%");
		setHeight("100.0%");*/
		
				
		panel_2.setContent(headerLayout);
		panel_2.setWidth("792px");
		panel_2.setHeight("100px");
		
		return panel_2;
		
		
	}
	
private Component createTabs() {
		
		
		
		VerticalLayout tabLayout = new VerticalLayout();
		tabLayout.setMargin(true);
		tabLayout.setSpacing(true);
		
		
		TabSheet tabSheet = new TabSheet();
		tabSheet.setSizeUndefined();
		
		
		tabLayout.addComponent(tabSheet);
		tabLayout.setMargin(true);
		
		VerticalLayout layout_home_tab = new VerticalLayout();
		layout_home_tab.setMargin(true);
		Component a = buildHomeContent();
		layout_home_tab.addComponents(a);
		
		VerticalLayout layout_myaccount_tab = new VerticalLayout();
		layout_myaccount_tab.setMargin(true);
		Component b = myAccount.buildMyAccountPage();
		layout_myaccount_tab.addComponent(b);
		
		VerticalLayout layout_customer_tab = new VerticalLayout();
		layout_customer_tab.setMargin(true);
//		Component c = customer.buildCustomerPage();
		Component c = new RoleManagementView().builRoleManagementPage();
		layout_customer_tab.addComponent(c);
		layout_customer_tab.setSizeFull();
		
		VerticalLayout layout_settings_tab = new VerticalLayout();
		layout_settings_tab.setMargin(true);
		Component d = settings.buildSettingsPage();
		layout_settings_tab.addComponent(d);
		
		VerticalLayout layout_policies_tab = new VerticalLayout();
		layout_policies_tab.setMargin(true);
		Component e = policy.buildPolicyPage();
//		Component e = new PolicyDetailsView().policyDetails();
//		Component e = new CreatePolicyView().createPolicy();
//		Component e = new AddMemberView().addMemberPage();
		
		layout_policies_tab.addComponent(e);
		
		VerticalLayout layout_payment_tab = new VerticalLayout();
		layout_payment_tab.setMargin(true);
		Component f = payment.buildPaymentsPage();
//		Component f = new PaymentDetailsView().buildPaymentDetailsPage();
//		Component f = new PaymentHistoryView().buildPaymentHistoryPage();
//		Component f = new PaymentSchedule().buildPaymentSchedulePage();
		layout_payment_tab.addComponent(f);
		
		VerticalLayout layout_claim_tab = new VerticalLayout();
		layout_claim_tab.setMargin(true);
		Component g = claims.buildClaimsPage();
//		Component g = new ClaimDocumentListView().buildClaimDocumentsPage();
		layout_claim_tab.addComponent(g);
		
		VerticalLayout layout_messages_tab = new VerticalLayout();
		layout_messages_tab.setMargin(true);
		Component h = msg.buildMessagesPage();
		layout_messages_tab.addComponent(h);
		
		
		tabSheet.addTab(layout_home_tab, "HOME");
		tabSheet.addTab(layout_myaccount_tab, "MY ACCOUNT");
		tabSheet.addTab(layout_customer_tab, "CUSTOMER");
		tabSheet.addTab(layout_myaccount_tab, "MY ACCOUNT");
		tabSheet.addTab(layout_settings_tab, "SETTINGS");
		tabSheet.addTab(layout_policies_tab, "POLICIES");
		tabSheet.addTab(layout_payment_tab, "PAYMENTS");
		tabSheet.addTab(layout_claim_tab, "CLAIMS");
		tabSheet.addTab(layout_messages_tab, "MESSAGES");
		
		tabSheet.addStyleName("tabTitle");
		
		
		
		tabSheet.getTab(layout_home_tab).setEnabled(true);
		
		Panel panel_1 = new Panel();
		panel_1.setContent(tabLayout);
		panel_1.setSizeUndefined();
		panel_1.setScrollLeft(5);
	
		
		
		return panel_1;
	}

private Component buildHomeContent() {
	Label label_1 = new Label("Welcome!");
	label_1.setStyleName("h2");
	
	HorizontalLayout layout_1 = new HorizontalLayout(label_1, createSearchBox() );
	layout_1.setSizeFull();
	layout_1.setSpacing(true);
	layout_1.setComponentAlignment(label_1, Alignment.MIDDLE_LEFT);
//	layout_1.setMargin(true);
	layout_1.setWidth("100%");
	
	
	Panel panel_1 = new Panel();
	Component panels = createPanels();
	
	VerticalLayout layout_3 = new VerticalLayout(layout_1, panels);
	layout_3.setSizeFull();
	layout_3.setSpacing(true);
//	layout_3.setComponentAlignment(panel_1, Alignment.MIDDLE_CENTER);
	layout_3.setMargin(true);
	layout_3.setWidth("100%");
	
	layout_3.setComponentAlignment(panels, Alignment.MIDDLE_CENTER);
	
	
//	layout_3.setComponentAlignment(panel_1, Alignment.MIDDLE_CENTER);
	
	panel_1.setContent(layout_3 );
//	panel_1.setContent(createPanels());
	panel_1.setWidth("792px");
	
	


	
//	panel_1.setSizeFull();
	
	
	return panel_1;
	
}

private Component createSearchBox() {
	
	
	
	TextField searchBox = new TextField();
	Button searchButton = new Button("Search");
	searchButton.setIcon(FontAwesome.SEARCH);
	
	
//	searchBox.setStyleName("search");
	
	HorizontalLayout searchLayout = new HorizontalLayout( searchBox, searchButton);
	searchLayout.setSpacing(true);
	
		
	searchLayout.setComponentAlignment(searchBox, Alignment.MIDDLE_RIGHT);
	searchLayout.setMargin(true);
	
	
//	searchBox.addStyleName("search");
	

	return searchLayout; 
	
}

private Component createPanels() {
	
	Panel panel_1 = new Panel("Mange");
	panel_1.setIcon(FontAwesome.WRENCH);
	panel_1.setSizeFull();
	panel_1.setHeight("250px");
	panel_1.setWidth("250px");
	Link a33 = new Link("SME Companies", null);
	a33.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	Link b33 = new Link("Role Management", null);
	b33.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	Link c33 = new Link("Claims", null);
	c33.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	Link d33 = new Link("Policies", null);
	d33.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	VerticalLayout links_3 = new VerticalLayout(a33,b33,c33,d33);
	links_3.setSizeUndefined();
	links_3.setSpacing(true);
	links_3.setMargin(true);
	panel_1.setContent(links_3);
	
	
	
	Panel panel_2 = new Panel("Tools");
	panel_2.setIcon(FontAwesome.COGS);
	panel_2.setSizeFull();
	panel_2.setHeight("250px");
	panel_2.setWidth("250px");
	Link a4 = new Link("View Users", null);
	a4.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	Link b4 = new Link("Role List", null);
	b4.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	Link c4 = new Link("View Claim Documents", null);
	c4.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	Link d4 = new Link("Create Policy", null);
	d4.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	VerticalLayout links_4 = new VerticalLayout(a4,b4,c4,d4);
	links_4.setSizeUndefined();
	links_4.setSpacing(true);
	links_4.setMargin(true);
	panel_2.setContent(links_4);
	
	Panel panel_3 = new Panel("Recent");
	panel_3.setIcon(FontAwesome.BULLHORN);
	panel_3.setSizeFull();
	panel_3.setHeight("250px");
	panel_3.setWidth("250px");
	Link a5 = new Link("Payments", null);
	a5.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	Link b5 = new Link("Claims", null);
	b5.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	Link c5 = new Link("Users", null);
	c5.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
//	Link d5 = new Link("Policies", null);
//	d5.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	VerticalLayout links_5 = new VerticalLayout(a5,b5,c5);
	links_5.setSizeUndefined();
	links_5.setSpacing(true);
	links_5.setMargin(true);
	panel_3.setContent(links_5);
	
	Panel panel_4 = new Panel("Authorize");
	panel_4.setIcon(FontAwesome.UNLOCK_ALT);
	panel_4.setSizeFull();
	panel_4.setHeight("250px");
	panel_4.setWidth("250px");
	Link a6 = new Link("Members", null);
	a6.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	Link b6 = new Link("Claims Pending", null);
	b6.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	Link c6 = new Link("Grant Access", null);
	c6.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
//	Link d6 = new Link("Create Policy", null);
//	d6.setIcon(FontAwesome.CHEVRON_CIRCLE_RIGHT);
	VerticalLayout links_6 = new VerticalLayout(a6,b6,c6);
	links_6.setSizeUndefined();
	links_6.setSpacing(true);
	links_6.setMargin(true);
	panel_4.setContent(links_6);
	
	Panel panel_5 = new Panel("New!");
	panel_5.setIcon(FontAwesome.STAR);
	panel_5.setSizeFull();
	panel_5.setHeight("200px");
	panel_5.setWidth("140px");
	Link a1 = new Link("Messages", null);
	a1.setIcon(FontAwesome.ENVELOPE_SQUARE);
	Link b1 = new Link("Members", null);
	b1.setIcon(FontAwesome.USER_MD);
	Link c1 = new Link("Claims", null);
	c1.setIcon(FontAwesome.FILE);
	VerticalLayout links_1 = new VerticalLayout(a1,b1,c1);
	links_1.setSizeUndefined();
	links_1.setSpacing(true);
	links_1.setMargin(true);
	panel_5.setContent(links_1);
	
	
	Panel panel_6 = new Panel("Add New");
	panel_6.setIcon(FontAwesome.PLUS_CIRCLE);
	panel_6.setSizeFull();
	panel_6.setHeight("200px");
	panel_6.setWidth("140px");
	Link a2 = new Link("SME", null);
	a2.setIcon(FontAwesome.USERS);
	Link b2 = new Link("Individual", null);
	b2.setIcon(FontAwesome.USER);
	VerticalLayout links_2 = new VerticalLayout(a2,b2);
	links_2.setSizeUndefined();
	
	links_2.setSpacing(true);
	links_2.setMargin(true);
	panel_6.setContent(links_2);
	
	 VerticalLayout v1 = new VerticalLayout();
	    v1.addComponent(panel_1);
	    v1.addComponent(panel_3);
//	    v1.setExpandRatio(panel_1, 1);
	    v1.setSizeFull();
//	    v1.setMargin(true);
	    v1.setSpacing(true);
	
	 VerticalLayout v2 = new VerticalLayout();
	    v2.addComponent(panel_2);
	    v2.addComponent(panel_4);
//	    v2.setExpandRatio(v1, 1);
	    v2.setSizeFull();
//	    v2.setMargin(true);
	    v2.setSpacing(true);
	    
	  VerticalLayout v3 = new VerticalLayout(panel_5,panel_6);
	  v3.setSpacing(true);
	  v3.setSizeFull();
	    
	 HorizontalLayout layout_5 = new HorizontalLayout(v3,v1,v2);
	 layout_5.setSizeUndefined();
	 layout_5.setSpacing(true);
	    
	 return layout_5;
}

	@Override
	public void enter(ViewChangeEvent event) {
		// TODO Auto-generated method stub
		
	}

}


